/** 
 * @Title: BBSCrawlOfAutohomeByHttpClient.java 
 * @Package com.zizo.autohome.bbs.crawl 
 * @Description: TODO
 * @author HeYan
 * @date 2016年8月30日 下午5:00:58 
 */
package com.zizo.autohome.bbs.crawl;

import java.util.List;
import java.util.Random;

import org.apache.http.NoHttpResponseException;

import com.zizo.util.HttpClientUtil;
import com.zizo.util.Util;

/**
 * @ClassName: BBSCrawlOfAutohomeByHttpClient
 * @Description: TODO
 * @author HeYan
 * @date 2016年8月30日 下午5:00:58
 * 
 */
public class BBSCrawlOfAutohomeByHttpClient implements Runnable {
	private int id;
	private List<String> ips;

	public BBSCrawlOfAutohomeByHttpClient(int id, List<String> ips) {
		super();
		this.id = id;
		this.ips = ips;
	}

	public void run() {
		int index = new Random().nextInt(ips.size());
		String hostAndPort = ips.get(index);
		String body = "";
		try {
			body = HttpClientUtil.send("http://club.autohome.com.cn/bbs/thread-c-498-" + id + "-1.html", null,
					hostAndPort.split(":")[0], Integer.parseInt(hostAndPort.split(":")[1]));
		} catch (NumberFormatException | NoHttpResponseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Util.downloadWebsite("C:/mnt/mirror/autohome/bbs/" + this.id / 10000, this.id + ".html", body);
		// Util.addFileToZip("C:/mnt/mirror/autohome/bbs/" + this.id / 10000 +
		// "/" + this.id + ".html",
		// "C:/mnt/mirror/autohome/bbs/" + this.id / 10000 + "/" + this.id +
		// ".zip");
		System.out.println(body);
		if (id % 10000 == 0) {
			System.out.println(this.id + "\t" + Util.getCurrentDateTime());
		}
	}
}
